// packagMy/pages/personal/myFootprint/myFootprint.js
import { collecProduct, contentProduct } from '../../../../config/config'
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
    videoUrl: getApp().globalData.videoUrl,
    listCur: 0,
    tabData:[{id: 0,name: '商品'},{id: 1,name: '内容'}],
    listData: [],
    page: 1,
    rows: 10,
    nomoreData: false,
    active: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success (res) {
        let statusBarHeight = res.statusBarHeight + 65
        console.log(statusBarHeight)
        that.setData({
          titleHeight: statusBarHeight + 'px'
        })
      }
    })
    that.getList(collecProduct)
  },
  // 获取足迹列表
  getList(type) {
    let that = this
    let formdata = {}
    formdata.page = that.data.page
    formdata.rows = that.data.rows
    app.reqFun.requestForm('POST',type,formdata,(res)=>{
      if(res.data.success === 1) {
        let records = res.data.data.records
        if (records.length < that.data.rows) {
          that.setData({
            nomoreData: true
          })
        }
        for (var i = 0, l = records.length; i < l; i++) {
          if(records[i].img) {
            if (records[i].img.split('/')[0] === 'marketing') {
              records[i].img = this.data.videoUrl + records[i].img
            } else {
              records[i].img = this.data.imgUrl + records[i].img
            }
          }
        }
        that.setData({
          listData: that.data.listData.concat(records)
        })
      }
    })
  },
  listSelect(e) {
    this.setData({
      listCur: e.currentTarget.dataset.id,
      listData: [],
      page: 1,
      rows: 10,
      nomoreData: false,
     })
    //  this.getList()
     if (this.data.listCur == 0) {
      this.getList(collecProduct)
    } else {
      this.getList(contentProduct)
    }
  },
   // 商品详情
   goodsInfo(option) {
    console.log('option', option)
   let skuid = option.currentTarget.dataset.skuid
   wx.navigateTo({
       url: '/packageShop/pages/goodsInfo/goodsInfo?id=' + skuid,
   })
 },
     // 内容详情
    mycontentDetail(option) {
     let id = option.currentTarget.dataset.data.resourceId
     let contentStatus = option.currentTarget.dataset.data.contentStatus
     let type = option.currentTarget.dataset.data.type
     let videoId = option.currentTarget.dataset.data.resourceId
     let columnId = option.currentTarget.dataset.data.extendId
     let name = option.currentTarget.dataset.data.title
     if (contentStatus == 2 || contentStatus == 3) {
       return
     } else {
       if (type === 'video') {
        wx.navigateTo({
          url: '/packageLive/pages/video/detail/video-swiper/video-swiper?id=' + videoId + '&name='+ name+ '&columnId=' + columnId,
        })
       } else {
        wx.navigateTo({
          url: '/packagBuy/pages/found/contentDetail/contentDetail?id=' + id,
        })
       }
     }
   },
  goreBack(e){
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomoreData) {
      this.setData({
        page: this.data.page + 1
      })
      if (this.data.listCur == 0) {
        this.getList(collecProduct)
      } else {
        this.getList(contentProduct)
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})